
TB_TOP := chunjun_dcu_tb
FILELIST := ./filelist.f
FILE ?= standard.f
TEST_NAMES =$(shell cat $(FILE))

TIMESCALE := -timescale=1ns/1ns
SIMULATOR_OPT := -sverilog -full64 -kdb -lca -debug_access +nospecify +notimingchecks +lint=TFIPC-L -debug_acc+all -debug_region+cell+encrypt -f ${FILELIST} -l comp.log +vcs+fsdbon

OUTPUT = cov_test

#code coverage command
CM = -cm line+cond+fsm+branch+tgl
CM_NAME = -cm_name ${OUTPUT}
CM_DIR = -cm_dir ./${OUTPUT}.vdb

com:
	vcs -full64  -LDFLAGS -Wl,--no-as-needed \
	-sverilog \
	-debug_acc+all -debug_region+cell+encrypt \
	+notimingcheck \
	+nospecify \
	+v2k \
	+memcbk \
	-l com.log \
	+define+UNIT_DELAY \
	+define+TSMC_INITIALIZE_MEM \
	-f ${FILELIST}  				  \
	${CM}                             \
	${CM_NAME}                        \
	${CM_DIR}

sim:
	./simv -l simv.log   +case_name=${case_name}             \
	${CM}                             						 \
	${CM_NAME}                        					     \
	${CM_DIR}

regression:			
	@echo "Running Tests with Coverage"
	make com;
	# rm -rf ${TEST_NAMES} ; mkdir ${TEST_NAMES}
	@rm -f all_tests.log 
	@for i in $(TEST_NAMES); do \
    	echo "Running test $$i" | tee -a all_tests.log; \
    	./simv +case_name=$$i ${CM} -cm_name $${i} ${CM_DIR}  2>&1 | tee -a all_tests.log; \
	done
	@echo "All tests completed. Logs are in all_tests.log"
	@echo "Printing all 'pass' entries from all_tests.log:"
	@grep -i "pass" all_tests.log || true
	@echo "Printing all 'fail' entries from all_tests.log:"
	@grep -i "fail" all_tests.log || true

cov:
	verdi -cov -covdir ${OUTPUT}.vdb &

merge:
	urg -full64 -dir cov_test.vdb /u/q2wang/cache/mcu/cpu_sim/cpu_top/sim/cov_test.vdb -dbname  crypto_merge.vdb -mapfile /u/q2wang/cache/mcu/crypto_sim/rtl/mapfile

merge_cov:
	verdi -cov -covdir crypto_merge.vdb &

verdi:
	verdi -sverilog -f ${FILELIST} -top ${TB_TOP} -ssf novas.fsdb -nologo & 

clean:
	rm -rf novas* csrc verdiLog simv* ucli* *.log ${OUTPUT}*.vdb ./DVEfiles 

all:
	make com; make sim

.PHONY: com sim verdi
